<template>
  <div class="content">
    <div v-for="(item, index) in titleList"
         :key="item" :class="{ active: active[index] }">
      <span @click="itemClick(index)">{{ item }}</span>
    </div>
    <span class="line" :style="{ left: left + 'px' }"></span>
  </div>
</template>

<script>
export default {
  name: "headerTitle",
  props: {
    titleList: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      active: [true, false],
      left: '22'
    }
  },
  methods: {
    itemClick(index) {
      this.active = this.active.map(item => item = false)
      this.$set(this.active, index, true)
      this.left = index ? '102' : '22'
      this.$emit('updateData', index + 1)
    }
  }
}
</script>

<style scoped lang="scss">

@import "headerTitle";

</style>
